﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EC18_ESHOP.Models;
using WebMatrix.WebData;


namespace EC18_ESHOP.Areas.Admin.Controllers
{

    public class AdminWareHouseController : Controller
    {

        EShopEntities db = new EShopEntities();
        //

        // GET: /Admin/AdminWareHouse/
        public ActionResult DetailDelivery()
        {
            return View();
        }
        public ActionResult DetailOder()
        {
            ViewBag.DetailOder = db.ORDER_TO_PROVIDER_DETAIL
                                       .Join(db.ORDER_TO_PROVIDER, d => d.OrderProviderId, de => de.OrderProviderId, (d, de) => new { d, de })
                                       .Where(k => k.d.OrderProviderId == k.de.OrderProviderId)
                                       .Select(k => k.d);

            return View();
        }
        public ActionResult NewDelivery()
        {
            return View();
        }
        #region Oder
        public ActionResult NewOder(int status = 0)
        {
            ViewBag.Status = status;
            ViewBag.ProviderID = new SelectList(db.PROVIDER, "ProviderId", "ProviderName");
            ViewBag.OderProID = new SelectList(db.ORDER_TO_PROVIDER, "OrderProviderID");
            ViewBag.arrOderProvider = db.ORDER_TO_PROVIDER.ToList();
            return View();

        }
        [HttpPost]
        public ActionResult NewOder(FormCollection con, ORDER_TO_PROVIDER oder)
        {


            //string oderProviderID= con["txtOderProviderId"];
            //string ProviderID = con["txtProductId"];
            //DateTime dateOder =DateTime.Parse(con["NgayLap"]);
            //DateTime dateDeli = DateTime.Parse(con["NgayNhan"]);
            //Decimal value = Decimal.Parse(con["txtValue"]);
            //string note = con["txtNote"];

            //oder.ProviderId = ProviderID;
            //oder.OrderProviderDate = dateOder;
            //oder.DeliveryDate = dateDeli;
            //oder.Value = value;
            //oder.Note = note;

            //db.ORDER_TO_PROVIDER.Add(oder);
            //db.SaveChanges();
            return RedirectToAction("NewOder");

        }
        #endregion
        public ActionResult UpdateDelivery()
        {
            return View();
        }

        public ActionResult UpdateOder()
        {
            return View();
        }

        public ActionResult AllDelivery()
        {
            ViewBag.AllDelivery = db.DELIVERY_NOTES.OrderByDescending(d => d.DeliveryDate)
                                           .Take(db.DELIVERY_NOTES.Count()).ToList();

            return View();
        }
        public ActionResult AllOder()
        {
            ViewBag.AllOder = db.ORDER_TO_PROVIDER.OrderByDescending(oder => oder.OrderProviderDate)
                                          .Take(db.ORDER_TO_PROVIDER.Count()).ToList();
            return View();
        }
        [HttpPost]
        public ActionResult Index()
        {
            return View();
        }


    }
}
